window.host = "http://114.116.69.140:8086";
// window.host = "http://192.168.1.107:8086"
window.imgHost = 'http://114.116.69.140:8888/';
window.search_url="http://114.116.69.140:8079"
function send_ajax(method, url, data, callback) {
    var user = JSON.parse(localStorage.getItem('user_info')) || {};
    if(user){
      var token = user.token;  
    }
    
    $.ajax({
        type: method, //提交方法是POST
        url: host + url,
        data: (method == 'post'||method == 'POST') ? JSON.stringify(data) : data,
        contentType: "application/json",
        xhrFields: {
            withCredentials: true
        },
        beforeSend: function beforeSend(request) {
            request.setRequestHeader("X-AUTH-TOKEN", token);
        },
        error: function error(_error) {
            //请求失败的回调方法 
            // alert('网络加载失败，请稍候再试!');
        },
        success: function success(data) {
            if (data.code == 200) {
                if (callback) {
                    callback(data);
                }
            } else {
                // if (data.msg == '商品不存在') {
                //     window.location.href = "/";
                // } else {
                //     // alert(data.msg);
                // }
            }
        }
    });
};
send_ajax('get', '/api/server/status', '', function callback(data) {
    if(data.code==200&&data.data==false){
        window.location.href='http://114.116.69.140:8888/server_expiration.html'
    }
});
$(document).ready(function () {
    var b_name = navigator.appName;
    var b_version = navigator.appVersion;
    var version = b_version.split(";");
    // var trim_version = version[1].replace(/[ ]/g, "");
    if (b_name == "Microsoft Internet Explorer") {
        /*如果是IE9及以下*/
        if (trim_version == "MSIE9.0" || trim_version == "MSIE8.0" || trim_version == "MSIE7.0" || trim_version == "MSIE6.0" || trim_version == "MSIE5.0") {
            alert("IE浏览器版本过低，请到指定网站去下载相关版本");
        }
    }
});
var isLinkage = false; //是否动了四级联动
//判断img有没有域名，没有域名加上域名
function isImgHttp(currentImg) {
    if (currentImg) {
        if (currentImg.indexOf('http') == -1 || currentImg.indexOf('http') > 0) {
            return imgHost + currentImg;
        } else {
            return currentImg;
        }
    }
};

jQuery(function ($) {
    var user = JSON.parse(localStorage.getItem('user_info')) || {};
    var goodsList = JSON.parse(localStorage.getItem('noUsers')) || [];
    var id = user.id;
    //小购物车
    var small_price = 0;
    var data;
    if (id) {
        var user = JSON.parse(localStorage.getItem('user_info')) || {};
        var id = user.id;
    } 
    if ($('.left_ul').length) {
        $('.isshow').mouseenter(function (e) {
            $(this).find('.ishide').show();
        }).mouseleave (function(){
            $('.ishide').hide();
        })
    };
});
//四舍五入
function keepTwoDecimalFull(num) {
    var result = parseFloat(num);
    if (isNaN(result)) {
        return num;
    }

    result = Math.round(num * 100) / 100;

    var s_x = result.toString();
    var pos_decimal = s_x.indexOf('.');
    if (pos_decimal < 0) {
        pos_decimal = s_x.length;
        s_x += '.';
    }
    while (s_x.length <= pos_decimal + 2) {
        s_x += 0;
    }
    return s_x;
};
(function(){
    var user = JSON.parse(localStorage.getItem('user_info')) || {};
    var id = user.id;
    if(id){
        var param={
        "YcUser": {
            "id": id,
            "@column": "id,balance,growth,point,level_id"
        }
        };
        send_ajax('post', '/get', param, function (data) {
        if(data.code==200){
                user.balance = data.YcUser.balance;
                user.growth = data.YcUser.growth;
                user.level_id = data.YcUser.level_id;
                user.point = data.YcUser.point;
                localStorage.setItem("user_info", JSON.stringify(user));
        }
        }); 
    }
})()